#ifndef MAINWINDOW_H
#define MAINWINDOW_H


#include <QMainWindow>
#include <QPen>
#include <QUndoStack>

class Model;
class View;
class QLabel;
class Line;
class Circle;
class QGraphicsRectItem;
class QGraphicsEllipseItem;
class QRect;
class QSlider;
class Select;
class QGraphicsItem;


class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(Model &model);
    int getDrawType(){ return m_drawType; }
    void startLine(qreal x,qreal y);
    void updateLine(qreal x,qreal y);
    void finishLine();
    void startArc(qreal x,qreal y);
    void updateArc(qreal x,qreal y);
    void finishArc();
    void startCircle(qreal x,qreal y);
    void updateCircle(qreal x,qreal y);
    void finishCircle();
    void startSelection(qreal x,qreal y);
    void updateSelection(qreal x,qreal y);
    void finishSelection();
    void finishZoomIn();
    void deselect();
    bool hitsSelectionBall(qreal x, qreal y);
    void mouseClick(qreal x, qreal y);
    void mouseRelease(qreal x, qreal y);
    void mouseDrag(qreal x, qreal y);

public slots:
    void about();
    void openFile();
    void saveFile();
    void saveAsFile();
    void selectColor();
    void setBarLabel(QString str);
    void setLineDrawType();
    void setCircleDrawType();
    void setArcDrawType();
    void zoomIn ();
    void undoZoom();
    void allZoom();
    void undo();
    void redo();
    void selectThickness();
    void setThickness();
    void select();
    void selectSolidLine();
    void selectDashLine();
    void selectDotLine();
    void selectDashDotLine();
    void selectDashDotDotLine();
    void selectErase();
    void selectMove();
    void selectScale();
    void selectRotate();
    void updateSelectedItems(qreal x, qreal y);
    void newProject();
    void help();

private:
    void buildMenuBar();
    void createActions();
    void buildToolBars();
    void buildStatusBar();

    bool m_mouseHold;

    Model& m_model;
    View* m_view;
    QPen m_pen;
    QSlider* m_penWidth;

    QUndoStack m_commandStack;
    QUndoStack m_zoomStack;

    //Tipo de ferramenta
    int m_drawType;   //TODO: use enum here
    int m_editType;   //TODO: use enum here
    bool m_isEdit;

    //Usado para guardar a posicao inicial numa movimentacao
    qreal m_startX;
    qreal m_startY;
    qreal m_startW;
    qreal m_startH;

    //Lista de items selecionados
    QList<QGraphicsItem*> m_selectedItems;

    //Elementos para auxiliarem a criacao de arcos
    bool m_arcState;

    //Elementos para manipulacao temporaria
    Line* m_currentLine;
    Circle* m_currentCircle;
    Select* m_currentSelection;

    //Retangulo e circulo de selecao
    QGraphicsRectItem* m_selectRect;
    QGraphicsEllipseItem* m_selectCircle;

    //
    QLabel* m_statusBarLabel;

    QAction* m_newAct;
    QAction* m_openAct;
    QAction* m_saveAct;
    QAction* m_saveAsAct;
    QAction* m_exitAct;
    QAction* m_editAct;
    QAction* m_redrawAct;
    QAction* m_copyAct;
    QAction* m_eraseAct;
    QAction* m_rotateAct;
    QAction* m_moveAct;
    QAction* m_scaleAct;
    QAction* m_trimAct;
    QAction* m_mirrorAct;
    QAction* m_breakAct;
    QAction* m_lineAct;
    QAction* m_circleAct;
    QAction* m_arcAct;
    QAction* m_colorAct;
    QAction* m_thicknessAct;
    QAction* m_typeSolidAct;
    QAction* m_typeDashAct;
    QAction* m_typeDotAct;
    QAction* m_typeDashDotAct;
    QAction* m_typeDashDotDotAct;
    QAction* m_windowAct;
    QAction* m_previousAct;
    QAction* m_allAct;
    QAction* m_helpAct;
    QAction* m_aboutAct;
    QAction* m_undoAct;
    QAction* m_redoAct;
    QAction* m_selectAct;
};


#endif // MAINWINDOW_H
